<template>
  <section class="row middle-span nav-info">
    <a @click="updateMenuCollapse(!menuCollapse)">
      <svg-icon iconName="jinjiancailiao" :class="{reversal:menuCollapse }" iconSize="30"></svg-icon>
    </a>

    <el-breadcrumb separator="/" class="nav-title">
      <transition-group name="breadcrumb">
        <el-breadcrumb-item v-for="item of routeInfos" :key="item.id">{{item.name}}</el-breadcrumb-item>
      </transition-group>
    </el-breadcrumb>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import { Component, Watch } from "vue-property-decorator";
import { Mutation, State } from "vuex-class";



@Component({
  components: {}
})
export default class NavInfo extends Vue {

  @State private menuCollapse!: boolean
  @State private menuResource!: any[]
  @Mutation private updateMenuCollapse!: (status: boolean) => void

  private routeInfos: any[] = []


  @Watch("$route.path", { immediate: true })
  private onRouteChange(val) {
    this.routeInfos = []
    if (val) {
      let info = this.menuResource.find(x => x.url === val)
      if (!info) return
      this.routeInfos.unshift(info)
      info = this.menuResource.find(x => x.id === info.parent)
      if (!info) return
      this.routeInfos.unshift(info)
    }
  }

}
</script>

<style lang="less" scoped>
.nav-info {
  .nav-title {
    margin-left: 20px;
  }
  .reversal {
    transform: rotate(180deg);
    transition: transform 0.5s;
  }
}
</style>

